/**
 * 产品管理js
 */
$(function () {
    initialPage();
    getGrid();
});

function initialPage() {
    $(window).resize(function () {
        $('#dataGrid').bootstrapTable({
            columns: [{
                checkbox: true
            }, {
                field: 'pn',
                align: 'center',
                title: '型号'
            }, {
                field: 'company',
                align: 'center',
                title: '公司'
            }, {
                field: 'usPrice',
                align: 'center',
                title: '美元价格'
            }, {
                field: 'chinaPrice',
                align: 'center',
                title: '人民币价格'
            }, {
                field: 'description',
                align: 'center',
                title: '描述'
            }, {
                field: 'deliveryTime',
                align: 'center',
                title: '货期'
            }, {
                field: "notes",
                title: "备注",
                width: "200px"
            }]
        });
    });
    vm.quantity = 1;
    vm.company = 'pickering';
    vm.pn = '40-968-001';
}

function getGrid() {
    $('#dataGrid').bootstrapTableEx({
        url: '../../product/query?_' + $.now(),
        height: $(window).height() - 54,
        striped:true,
        queryParams: function () {
            return {
                company: vm.company,
                pn: vm.pn,
                quantity: vm.quantity
            };
        },
        columns: [{
            checkbox: true
        }, {
            field: 'pn',
            align: 'center',
            title: '型号'
        }, {
            field: 'company',
            align: 'center',
            title: '公司'
        }, {
            field: 'usPrice',
            align: 'center',
            title: '美元价格'
        }, {
            field: 'chinaPrice',
            align: 'center',
            title: '人民币价格'
        }, {
            field: 'description',
            align: 'center',
            title: '描述'
        }, {
            field: 'deliveryTime',
            align: 'center',
            title: '货期'
        }, {
            field: "notes",
            title: "备注",
            width: "200px"
        }]
    })
}

var vm = new Vue({
    el: '#dpLTE',
    data: {
        company: null,
        pn: null,
        quantity: null
    },
    methods: {
        load: function () {
            $.ajax({
                type: 'POST',
                url: '../../product/query?_' + $.now(),
                data: {
                    "company": vm.company,
                    "pn": vm.pn,
                    "quantity": vm.quantity
                },
                dataType: 'json',
                success: function (data) {
                    var dataGrid = $('#dataGrid');
                    for (var i =0; i < data.data.length; i++) {
                        dataGrid.bootstrapTable('insertRow', {
                            index: dataGrid.bootstrapTable('getData').length,
                            row: data.data[i]
                        });

                    }
                }
            });
        },
        clear: function () {
            $('#dataGrid').bootstrapTable('removeAll');
        }
    }
});